<?php
require_once WEB_ROOT.'/application/library/Pager.php';
$pager = new Pager(array(
    'rowperpage' =>10,
    'total_rows' =>$Bus->Rule->countTotalRow(),
    'currentpage'=>(isset($_GET['page']) && intval($_GET['page']) > 0)?$_GET['page']:1,
    'link'       =>url('admin','rules-manager')
));


$rules = $Bus->Rule->getItemsPager($pager->getRowStart() ,$pager->getRowPerPage());
$groups = $Bus->Group->getAllData();

$index = 1; 
include 'component/header.php';
include 'component/slidebar.php'; 
?>
<script type="text/javascript">
$(function(){
    $(".btStatus").click(function(){
        var img = $(this).children('img');
        var link = $(this).attr('href');
        $.ajax({
            url: link,
            success: function(data){
                if(img.attr('src') == "css/images/icon/success.png"){
                    img.attr('src','css/images/icon/error.png');
                }else{
                    img.attr('src','css/images/icon/success.png');
                }
            }
        });
        return false;
    });
});
</script>
<!-- BEGIN CONTENT -->
<div id="content">
    <div class="box-out">
    	<div class="box-in">
    		<div class="box-head"><h1>Quản lý phân quyền.</h1></div>
    		<div class="box-content">
                <div class="table">
    				<form>
    					<table>
    						<thead>
    							<tr>
    								<td><div>Group</div></td>
                                    <td><div>Module</div></td>
                                    <td><div>Action</div></td>
                                    <td><div>Title Page</div></td>
                                    <td align="center"><div>Allow</div></td>
    							</tr>
    						</thead>
    						<tbody>
                            <?php foreach($rules as $key=> $rule) { $class = ($index%2)?"class='even'":"class='odd'"; ?>
    							<tr>
                                    <!-- Lấy Tên nhóm -->
                                    <?php $group = $Bus->Group->getItemById($rule->groups_idgroups);?>
    								<td><div <?php echo $class;?> ><?php echo $group->groups_name; ?></div></td>
                                    
                                    <!-- Lấy tên module và tên action -->
                                    <?php
                                    $action  = $Bus->Action->getItemById($rule->actions_idactions);
                                    $module = $Bus->Module->getItemById($action->modules_idmodules);
                                    ?> 
                                    <td><div <?php echo $class;?> ><?php echo $module->modules_name; ?></div></td>
                                    <td><div <?php echo $class;?> ><?php echo $action->actions_name; ?></div></td>
                                    <td><div <?php echo $class;?> ><?php echo $action->actions_title; ?></div></td>
                                    <td>
                                        <div align="center" <?php echo $class;?> >
                                            <?php if($rule->rules_allow){?>
                                            <a title="Thay đổi trạng thái" class="btStatus tooltip" href="<?php echo url('admin','rules-update', array('gr'=>$group->idgroups,'ac'=>$action->idactions));?>">
                                                <img src="css/images/icon/success.png" />
                                            </a>
                                            <?php }else{?>
                                            <a title="Thay đổi trạng thái" class="btStatus tooltip" href="<?php echo url('admin','rules-update', array('gr'=>$group->idgroups,'ac'=>$action->idactions));?>" >
                                                <img src="css/images/icon/error.png" />
                                            </a>
                                            <?php } ?>
                                        </div>
                                    </td>
    							</tr>
                            <?php $index++; } ?>
    						</tbody>
    					</table>
                        <div class="pagination">
                            <?php  $pager->showPager(); ?>
                        </div>
                        
    				</form>
    			</div>
    		</div><!-- end div .box-content -->
    	</div><!-- end div .box-in -->
</div><!-- end div #content -->
<!-- END CONTENT -->

<?php
include 'component/footer.php'; 
?>
